/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package business;

/**
 *
 * @author stana
 */
public class O2Gateway implements SmsGateway{

    private final int SMS_LIMIT = 29;
    Emailer em = new Emailer();

    @Override
    public void sendSms(String sms, String number)
    {
        int limitPlus=SMS_LIMIT-1;//do kazde zpravy se prida info o kolikatou zprovu jde
        int i = sms.length() / (limitPlus);//zjisti na kolik casti musi rozdelit zpravu
        number=number+"@sms.cz.o2.com";
        String cutMessage = "";
        int j;
        for (j = 0; j < i; j++)//postupne odesle jednotlive casti SMS
        {
            cutMessage = (j+1)+sms.substring(j * limitPlus, (j + 1) * limitPlus);
            System.out.println("posilam: number-" + number + "msg " + cutMessage);
            em.sendEmail( number, "", cutMessage);
        }
        if (sms.length() % limitPlus != 0)//odesle poslednio dil SMS, pokud nejaky je
        {
            cutMessage = (j+1)+sms.substring(i * limitPlus);
            System.out.println("posilam: number-" + number + "msg " + cutMessage);
            em.sendEmail( number, "", cutMessage);
        }
    }

}
